<template>
    <van-nav-bar title="通知" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-form @submit="onSubmit" class="my-form">
      <van-field name="id" label="用户id" v-model="id" readonly />
    <van-field name="userName" v-model="userName" label="姓名" placeholder="请输入姓名" />
  <van-field name="stuNo" v-model="stuNo" label="学号" placeholder="请输入学号" />
  <van-field name="phone" v-model="phone" type="tel" label="手机号" placeholder="请输入手机号" />
  <van-field name="gender" label="性别">
  <template #input>
    <van-radio-group v-model="gender" direction="horizontal">
      <van-radio name="0">男</van-radio>
      <van-radio name="1">女</van-radio>
    </van-radio-group>
  </template>
</van-field>
  <van-field name="email" v-model="email" label="邮箱" placeholder="请输入邮箱" />
  <van-field name="birth" v-model="birth" label="生日" placeholder="请输入生日" />
  <!-- 提交按钮 -->
<div style="margin: 16px">
      <van-button round block type="primary" native-type="submit">
        提交修改
      </van-button>
    </div>
  </van-form>

    <!-- 可以使用 CellGroup 作为容器 -->
    <!-- <van-cell-group inset>
  <van-field v-model="value" label="文本" placeholder="请输入用户名" />
</van-cell-group> -->

</template>
    
<script setup lang='ts'>
import { ref, onUnmounted, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import {getSelfMsg1, EditInfo ,editInfo} from '../api/api';
import $bus from "../config/eventBus";
import { showToast } from 'vant';

// 获取传递的 通知的 id 值
const router = useRouter();
// 可以使用 route 来获取 参数值
const route = useRoute();
const id = ref<string>('');
  const userName = ref<string>('');
    const stuNo = ref<string>('');
      const email = ref<string>('');  
        const phone= ref<string>('');
          const birth= ref<string>('');
            const deptId= ref<string>('');
              const gender= ref<string>('');
  
// 发送请求获取个人信息
onMounted(async () => {
  // let res = await getSelfMsg()
  let res1 = await getSelfMsg1()
    // console.log(res, 6666)
    console.log(res1, 411)
    // console.log(res1.data.data.userName, 333)
    if (res1.data.code === 0) {
        // showToast(res.data.pass)
        id.value= res1.data.data.id
        userName.value= res1.data.data.userName
        stuNo.value= res1.data.data.stuNo
        email.value= res1.data.data.email
        phone.value= res1.data.data.phone
        birth.value= res1.data.data.birth
        gender.value= res1.data.data.gender

    } else {
      showToast(res1.data.msg)
    }
});

// 提交修改请求
const onSubmit = async (values: editInfo) => {
    console.log('修改的参数', values)
    console.log(phone);
    
    const res = await EditInfo(values)
    console.log(res,"5")
    showToast(res.data.msg)

};

//  返回上一页
const onClickLeft = () => history.back();
//登陆页不要tabBar
onMounted(() => {
    $bus.emit("tabBarHide", false);
})

//页面离开记得销毁
onUnmounted(() => {
    $bus.emit("tabBarHide", true);
})
</script>
    
<style scoped lang='scss'>
.box{
    margin: 15px;
    
}

</style>